import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-09-24
 * Time:21:14
 */
class Card{
    public  String suit;
    public  int rank;

    public Card(String suit, int rank) {
        this.suit = suit;
        this.rank = rank;
    }

    @Override
    public String toString() {
        return " [ " + suit + " " + rank + " ]";
    }
}
public class CardDemo {
    public static String[] suits = {"♠","♥","♣","♦"};
    public static List<Card> buyCards(){
        List<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = suits[i];
                Card card = new Card(suit,j);
                cards.add(card);

            }

        }
        return cards;
    }
    public static void swap(List<Card> cards,int x,int y){
        Card tmp = cards.get(x);
        cards.set(x,cards.get(y));
        cards.set(y,tmp);
    }
    public static void shuute(List<Card> cards){
        int size = cards.size();
        for (int i = size-1; i > 0; i--) {
            Random random = new Random();
            int random1 =random.nextInt(i);//[0.i)
            swap(cards,random1,i);
        }
    }

    public static void main(String[] args) {
        List<Card> cards = buyCards();
        System.out.println(cards);

        shuute(cards);
        System.out.println(cards);

        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List<List<Card>> hands = new ArrayList<>();//二维数组
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        for (int i = 0; i < 17; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌" + hands.get(0));
        System.out.println("第二个人的牌" + hands.get(1));
        System.out.println("第三个人的牌" + hands.get(2));
        System.out.println(cards);
    }
}
